<!DOCTYPE html>
<html>
<head>
  <link href="https://cdn.bootcss.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
  <link href="https://cdn.bootcss.com/prism/1.14.0/themes/prism.min.css" rel="stylesheet">
  <link href="https://cdn.bootcss.com/prism/1.14.0/plugins/toolbar/prism-toolbar.min.css" rel="stylesheet">

  <style>
    .highlight {
      padding: 9px 14px;
      margin-bottom: 14px;
      background-color: #f7f7f9;
      border: 1px solid #e1e1e8;
      border-radius: 4px;
    }
    .summary {
      font-weight: bold;
    }
    .line:hover {
      cursor: pointer;
    }
    p.line {
      margin: 0;
    }
    ._form {
      margin-top: 15px;
    }
    .method-get {
      color: blue;
    }
    .method-post {
      color: green;
    }
  </style>
</head>

<body class="container">

<nav class="navbar navbar-default" role="navigation">
  <div class="container-fluid">
    <div class="navbar-header">
      <a class="navbar-brand" href="javascript:">Logger</a>
    </div>
    <div>
      <ul class="nav navbar-nav">
        <li><a href="#" onclick="clearLogTable()">清空log表</a></li>
      </ul>
    </div>
  </div>
</nav>

{!! $list->render() !!}

@forelse($list as $log)
  <div class="row highlight">
    <div class="row">

      <div class="col-md-12">
        <p class="line" data-id="{{$log['id']}}">{{$log['created_at']}} :
          @if($log['is_deprecated'])<del>@endif
            <code class="@if($log['method'] == 'GET') method-get @elseif($log['method'] == 'POST') method-post @endif">{{$log['method']}}</code> <code>{{$log['pathinfo']}}</code>
            @if($log['is_deprecated'])</del>@endif
          <span class="summary pull-right">{{$log['tag']}}: {{$log['summary']}}</span>
        </p>

        <div class="_form form-{{$log['id']}}" style="display: none">
          <p> 完整请求路径: <code>{{$log['full_url']}}</code></p>
          <p><a href="{{$log['doc_url']}}" target="_blank">点击查看文档: {{$log['doc_url']}}</a></p>
          <p>
            <button class="btn btn-default btn-small show-modal"
                    data-content="{{$log['request_header']}}"
                    data-title="请求头内容">查看请求头</button>
            <button class="btn btn-default btn-small show-modal"
                    data-content="{{$log['request_body']}}"
                    data-title="请求体内容">查看请求体</button>
            <button class="btn btn-default btn-small show-modal"
                    data-type="json"
                    data-content="{{json_encode(json_decode($log['response_body']), JSON_UNESCAPED_UNICODE)}}"
                    data-title="响应内容">查看响应内容</button>
          </p>
        </div>
      </div>

    </div>
  </div>
@empty
  暂时没有数据
@endforelse

<div class="modal fade" id="modal" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="modal-title">模态框（Modal）标题</h4>
      </div>
      <div class="modal-body">
        <pre><code class="language-json" id="modal-content"></code></pre>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
      </div>
    </div>
  </div>
</div>
<input type="hidden" id="code-content">

<script src="https://cdn.bootcss.com/jquery/3.0.0/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script src="https://cdn.bootcss.com/prism/1.14.0/prism.min.js"></script>
<script src="https://cdn.bootcss.com/prism/1.14.0/components/prism-json.min.js"></script>
<script src="https://cdn.bootcss.com/prism/1.14.0/plugins/toolbar/prism-toolbar.min.js"></script>

<script>
  $(function () {
      $('.show-modal').click(function () {
          const content = $(this).data('content');
          const title = $(this).data('title');
          const type = $(this).data('type');
          window.code = content;

          $('#modal-title').html(title);
          if (type == 'json') {
              $('#modal-content').html(JSON.stringify(content, null, 2));
          } else {
              $('#modal-content').html(content);
          }
          $('#code-content').val(window.content);
          $('#modal').modal('show');
          // Prism.highlightAll();
      });

      $('.line').click(function () {
          $('.form-' + $(this).data('id')).toggle();
      });
  });
</script>
<script>
    (function(){
        Prism.plugins.toolbar.registerButton('copy-to-clipboard', function () {
            var linkCopy = document.createElement('a');
            linkCopy.textContent = 'Copy';

            linkCopy.addEventListener('click', function () {
                var code = document.getElementById("code-content");
                code.select();
                document.execCommand("Copy");
            });

            return linkCopy;
        });
    })();
</script>
<script>
  function clearLogTable() {
      $.get('_clear_log', {}, () => {
          location.reload();
      })
  }
</script>
</body>
</html>